//
//  KoiBaseToolbarModifier.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 13.04.25.
//

import Foundation
import SwiftUI
struct KoiToolbarModifier : ViewModifier {
    
    @Environment(\.presentationMode) var presentationMode;
    
    var title: Text
    
    init(title: Text) {
        //Use this if NavigationBarTitle is with Large Font
        //UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.red]
        //Use this if NavigationBarTitle is with displayMode = .inline
        //UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.red]
        self.title = title
    }
    
    func body(content: Content) -> some View {
        content
            .toolbar{
                ToolbarItem(placement: .navigationBarLeading) {
                    Button (action:{
                        presentationMode.wrappedValue.dismiss()
                    }) {
                        Image(systemName: "chevron.backward")
                            .padding(5)
                            .foregroundColor(Color.koiColorTitle)
                    }
                }
            }
            .navigationBarTitle(title, displayMode: .inline)
            .navigationBarBackButtonHidden()
    }
}

extension View {
    
    func koiToolbar(title: Text) -> ModifiedContent<Self, KoiToolbarModifier>{
        return modifier(KoiToolbarModifier(title: title))
    }
}
